#!/bin/sh

/usr/bin/mysqld_safe > /dev/null 2>&1 &

mysqladmin --silent --wait=30 ping

mysql -uroot -e "CREATE USER 'homestead'@'%' IDENTIFIED BY '123456'"
mysql -uroot -e "CREATE USER 'homestead'@'localhost' IDENTIFIED BY '123456'"
mysql -uroot -e "FLUSH PRIVILEGES"
mysql -uroot -e "CREATE SCHEMA homestead"
mysql -uroot -e "CREATE DATABASE zcurd_base"
mysql -uroot -e "CREATE DATABASE zcurd_busi"
mysql -uroot -e "GRANT ALL PRIVILEGES ON zcurd_base.* TO 'homestead'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION"
mysql -uroot -e "GRANT ALL PRIVILEGES ON zcurd_busi.* TO 'homestead'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION"

mysql -uroot zcurd_base < /db/zcurd_base.sql
mysql -uroot zcurd_busi < /db/zcurd_busi.sql

echo "=> Done!"

echo "========================================================================"
echo "You can now connect to this MariaDB Server using:"
echo ""
echo "    mysql -uhomestead -psecret -h<host> -P<port>"
echo ""
echo "Please remember to change the above password as soon as possible!"
echo "MariaDB user 'root' has no password but only allows local connections"
echo "========================================================================"

mysqladmin -uroot shutdown
